package sctu.edu.java.year2016.team08.project;

/**
 * Created by 松红 on 2016/6/29.
 */

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Client extends JFrame {
    public Client() {
        JPanel contentPane = new JPanel();
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);
        JTextField field = new JTextField();
        contentPane.add(field, BorderLayout.NORTH);
        JPasswordField field1 = new JPasswordField();
        field1.setEchoChar('*');
        contentPane.add(field1, BorderLayout.CENTER);
        JButton button1 = new JButton("点击登陆");
        contentPane.add(button1, BorderLayout.SOUTH);
        setVisible(true);
        setTitle("IT运维后台登入系统");
        setSize(400, 110);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        button1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                try {
                    Class.forName("com.mysql.jdbc.Driver");
                } catch (ClassNotFoundException e2) {
                    e2.printStackTrace();
                }
                try {
                    String url = "jdbc:mysql://localhost:3306/lsongh";
                    String user = "root";
                    String Password = "";
                    Connection conn = DriverManager.getConnection(url, user, Password);
                    String string = null;
                    string = field.getText();
                    String sql3 = "select * from pwd where username='" + string + "'  ";
                    PreparedStatement ps3 = conn.prepareStatement(sql3);
                    ResultSet rs = ps3.executeQuery(sql3);
                    int popedom;
                    while (rs.next()) {
                        popedom = rs.getInt(4);
                        if (popedom == 1) {
                            AScanf scanf = new AScanf();
                            scanf.setVisible(true);
                        }
                        field.setText(" ");
                    }
                    conn.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }

            }
        });

    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new Client();
    }

}
